#region File Description
//  XAEnima 
//  License: GNU/GPL
//  Developer: Federico Leonardo Motta
//  Description: XAEnima
#endregion

#region Using Statements
using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Storage;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using XAEnima.Core;
using XAEnima.Core.GameManager;
using SharedContent;
#endregion

namespace XAEnima
{
     public class XAEnimaMain : Microsoft.Xna.Framework.Game
    {
        GraphicsDeviceManager graphics;
        SpriteBatch spriteBatch;
        StorageDevice device;

        public XAEnimaMain()
        {
            graphics = new GraphicsDeviceManager(this);
            Content.RootDirectory = "Content";
            FileManager fm = new FileManager();
            SharedOptions opt = new SharedOptions();
            try { 
                opt = fm.GetOptions(device); 
            }catch(System.IO.FileNotFoundException){
                opt.IsFullscreen = false;
                opt.ResolutionX = 1024;
                opt.ResolutionY = 768;
                opt.Stimolation = true;
                fm.DoSave(device,opt);
            }
            Console.WriteLine("Runtime Logs:");
            Console.WriteLine("-------------");
            graphics.IsFullScreen = opt.IsFullscreen;
            graphics.PreferredBackBufferHeight = opt.ResolutionY;
            graphics.PreferredBackBufferWidth = opt.ResolutionX;
            //this.Components.Add(new ComunicationManager(this));
            Services.AddService(typeof(SharedContext), new SharedContext()
            {
                sprite_batch = null
            });
            StateManager.graphic = graphics;
        }

        /// <summary>
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base.Initialize will enumerate through any components
        /// and initialize them as well.
        /// </summary>
        protected override void Initialize()
        {
            (Services.GetService(typeof(SharedContext)) as SharedContext).sprite_batch = new SpriteBatch(GraphicsDevice);
            this.GetGraphic(graphics);
            this.StartIntro();

            base.Initialize();
        }


        protected override void LoadContent()
        {

        }


        protected override void UnloadContent()
        {

        }

        protected override void Update(GameTime gameTime)
        {
            // Allows the game to exit
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
                this.Exit();


            base.Update(gameTime);
        }


        protected override void Draw(GameTime gameTime)
        {
            GraphicsDevice.Clear(Color.Black);


            base.Draw(gameTime);
        }
    }
}